var app = getApp()
var _request = require("../../utils/request.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activelist:'',
    active1: 0,
    active2: 0,
    bannerlist:[],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 2000,
    circular:true,
    yidou:''//意豆合集
  },
  toDetails(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  toDetails2(){
    wx.navigateTo({
      url:'/pagesb/detailed/detailed'
    })
  },
  loadAdvertisingList: function() {
    const self = this
    _request.postObj('/marketing/advertising/getlist', {
      type: 2
    }, app.globalData.mallType).then((res) => {
      // console.log(res)
      if (res.data.code === 200) {
        self.setData({
          bannerlist: res.data.data.rows || []
        })
      }
    })
  },
  getcommoditylist(){
    _request.get('/commodity/getcommoditylist', {}, app.globalData.mallType).then((res) => {
      if (res.data.code === 200) {
        this.setData({
          activelist: res.data.data || []
        })
      }
    }).catch((error) => {
      console.log(error, 'error');
    })
  },
  getyidounum(){//获取意豆
    let userId = wx.getStorageSync('userId');
    const self = this

    _request.get('/wallet/getCoinInfo', {
      id: userId,
      userId
    }).then((res) => {
      this.setData({
        yidou:res.data.data
      })
    }).catch((error) => {
      console.log(error, 'error');
    })
  },
  goorderlist(){
    console.log(111)
    wx.navigateTo({
      url: '/pagesb/orderlist/orderlist',
    })
  },
  goyidoulist(){
    wx.navigateTo({
      url: '/pagesb/yidoulist/yidoulist',
    })
  },
  bindtaps(e){
    this.setData({
      active1:e.currentTarget.dataset.index
    })
    console.log(e.currentTarget.dataset.id)
  },
  bindtaps2(e){
    this.setData({
      active2:e.currentTarget.dataset.index
    })
  },
  golist(e){
    wx.navigateTo({
      url: '/pagesb/yidoulist/yidoulist?type='+e.currentTarget.dataset.type,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(1111111111111)
    this.loadAdvertisingList();
    this.getyidounum()
    this.getcommoditylist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})